/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package handling.login.handler;

import client.LoginCrypto;
import client.MapleClient;
import database.DatabaseConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author 몽키프 (monkey_f@naver.com)
 */
public class LoginAutoRegister {
        public static void registerAccount(MapleClient c, String name, String password, boolean gender) {//true=여자,false=남자
        Connection connect = DatabaseConnection.getConnection();
        PreparedStatement query = null;
        ResultSet result = null;
        try {
           query = connect.prepareStatement("INSERT INTO accounts (name, password, socialNumber, gender) VALUES (?, ?, ?, ?)", DatabaseConnection.RETURN_GENERATED_KEYS);
           query.setString(1, name);
           query.setString(2, LoginCrypto.hexSha1(password));
           query.setInt(3, 1111111); //주민등록번호
           if (gender) {
           query.setInt(4, 1);
           } else if (!gender) {
           query.setInt(4, 0);
           }
           query.executeUpdate();
        } catch (Exception error) {
             error.printStackTrace();
        } finally {
             try {
                if (connect != null) {
                    connect = null;
                }
                if (query != null) {
                    query.close();
                }
                if (result != null) {
                    result.close();
                }
             } catch (Exception error) {
             }
             }
        }
    }
